//
//  CZMainTabBar.swift
//  1215微博终极项目
//
//  Created by chok崋 on 15/12/16.
//  Copyright © 2015年 周卓华. All rights reserved.
//

import UIKit

class CZMainTabBar: UITabBar {

   private let count = 5
    //添加到父类时调用
   override func layoutSubviews() {
        super.layoutSubviews()
        //设置每个按钮的宽
        let width = self.bounds.width / CGFloat(count)
        //设置按钮的高
        let hight = self.bounds.height
        //初始化第一个按钮的frame,进行对比
        let frame = CGRect(x: 0, y: 0, width: width, height: hight)
    var index :CGFloat = 0
    for view in self.subviews
    {
        if view is UIControl && !(view is UIButton)
        {
            view.frame = CGRectOffset(frame, index*width , 0)
            index += index == 1 ? 2:1
        }
        
    }
    compaseButton.frame = CGRectOffset(frame, width * 2.0, 0)
}
    
    lazy var compaseButton:UIButton = {
    
        let btn = UIButton()
        //设置背景图片
        btn.setBackgroundImage(UIImage(named:"tabbar_compose_button" ), forState: UIControlState.Normal)
       //设置选中的背景图片
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        btn.setImage(UIImage(named:"tabbar_compose_icon_add" ), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Selected)
        //添加到父容器中
        self.addSubview(btn)
        return btn
    }()
    
    
    
}
